﻿namespace Mathematics.Expressions
{
    public class UserDefinedFunction:FunctionDefinition
    {

        public UserDefinedFunction(string name, Domain functionDomain, params ParameterDefinition[] parameters)
            :base(name,parameters)
        {
            FunctionDomain = functionDomain;
        }

        public Domain FunctionDomain { get; private set; }

        internal override ExpressionValue Invoke(FunctionCall call)
        {
            foreach (var parameter in call.Parameters)
                FunctionDomain.AssignVariable(parameter.Name, parameter.Value.Evaluate());

            
            var value= FunctionDomain.Evaluate();
            return value;
        }

        public override bool CanEvaluate()
        {
            return FunctionDomain.CanEvaluate();
        }
    }
}
